package com.userfactssample.client.client.framework;

import com.smartgwt.mobile.client.widgets.Canvas;
import com.smartgwt.mobile.client.widgets.layout.Layout;
import com.userfactssample.client.client.framework.formItems.UMFormItem;

public abstract class UMContainerComponent extends UMComponent<Layout> {
	public UMContainerComponent(Layout uiComponent) {
		super(uiComponent);
	}
	
	private Layout getLayout()	{
		return (Layout) uiComponent;
	}
	
	public void add(UMComponent<?> widget) {
		getLayout().addMember(widget.getUiComponent());
	}
	
	public void addMember(Canvas uiComponent) {
		getComponent().addMember(uiComponent);
	}
	
	public void addMember(UMFormItem uiComponent) {
		addMember(uiComponent.getFormItem());
	}
	
	public void addMember(UMComponent<?> uiComponent) {
		addMember(uiComponent.getUiComponent());
	}
	
	public void removeAll(){
		Canvas[] children = getLayout().getMembers();
		for(int i =0; i<children.length; i++){
			try{
				children[i].destroy();
			}
			catch(Exception ex){
				
			}
		}
	}

	public void removeMember(Canvas uiComponent) {
		getLayout().removeMember(uiComponent);
	}
	
	public void removeMember(UMComponent<?> uiComponent) {
		getLayout().removeMember(uiComponent.getUiComponent());
	}
	
	public void setLayoutMargin(int layoutMargin) {
		getLayout().setLayoutMargin(layoutMargin);
	}

	public void setMarginLeft(Integer layoutLeftMargin) {
		getLayout().setLayoutLeftMargin(layoutLeftMargin);
	}
	
	public Integer getMarginLeft() {
		return getLayout().getLayoutLeftMargin();
	}
	
	public void setMarginRight(Integer layoutRightMargin) {
		getLayout().setLayoutRightMargin(layoutRightMargin);
	}
	
	public Integer getMarginRight() {
		return getLayout().getLayoutRightMargin();
	}
	
	public void setMarginTop(Integer layoutTopMargin) {
		getLayout().setLayoutTopMargin(layoutTopMargin);
	}
	
	public Integer getMarginTop() {
		return getLayout().getLayoutTopMargin();
	}
	
	public void setMarginBottom(Integer layoutBottomMargin) {
		getLayout().setLayoutBottomMargin(layoutBottomMargin);
	}
	
	public Integer getMarginBottom() {
		return getLayout().getLayoutBottomMargin();
	}
	
	public void setBackgroundImage(String backgroundImage) {
		getLayout().getElement().getStyle().setBackgroundImage(backgroundImage);
	}
}
